import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.Vector;


public class invertedIndex {

	
	
	
	public void InvertedIndex(FileInputStream documentFile, 
									String query , String Algorithm)
	{
		Hashtable<Integer , Integer> howManyDocContainQuery 
									= new Hashtable<Integer , Integer>();
		
	}
	
	public static void main(String[] args) throws FileNotFoundException
	{
		invertedIndex wordindex = new invertedIndex();
		
		if(args.length < 3)
		{
			System.out.println("you might miss some args"+
					"try again");
			
		}
		else
		{
			if ((args[2]).equalsIgnoreCase("cosine") 
					|| (args[2]).equalsIgnoreCase("boolean"))
			{
				FileInputStream filestream = new FileInputStream(args[0]);
				wordindex.InvertedIndex(filestream, args[1], args[2]);
				
			}
			else
			{
				System.err.println("Error: Input type will " +
											"be cosine or boolean");
			}
			
		}
		
	}
	class Position
	{
		private String doc_id;
		private int address;
		
		public Position(String doc_id , int address)
		{
			doc_id = this.doc_id;
			address = this.address;
		
		}
	}
	/*
	 *  inveredindex<dic_id, keyword, position>
	 */
	class InvertedIndex_ADT
	{ 
		private TreeMap<String, TreeMap<String, Vector<Integer>>> invertedindex;
		
		Position possition;
		/*
		 * first, it is returning the  term and position of term
		 * 
		 * param: key: keyword that we want to find for first position.
		 * **/
		public Position first(String key){
			TreeMap<String ,  Vector<Integer>> 
				termAndPosition = invertedindex.get(key);
		Map.Entry<String, Vector<Integer>> getFirstValue = termAndPosition.firstEntry();
		Vector<Integer> vector = getFirstValue.getValue();
		Collections.sort(vector);
		
		return possition = new Position(getFirstValue.getKey() , vector.get(0));
			
			//HashMap.Entry<String, Vector<Integer>> ValueList = termAndPosition.
			
		}
		/* firstDoc: returns the docid the first document containing the ther key
		 * param:  key: term t
		 * 
		 * */
		public Position firstDoc(String key){
			
			
			return possition;
		}
		
		public Position next(String key, int p){
			
			return possition;
		}
		
		public Position nextDoc(String key, int p){
			
			return possition;
		}
		/*
		 * first, it is returning the  term and position of term
		 * 
		 * param: key: keyword that we want to find for last position.
		 * **/
		public Position last(String key){
			int maxLenVector = 0;
			TreeMap<String ,  Vector<Integer>> 
			termAndPosition = invertedindex.get(key);
			Map.Entry<String, Vector<Integer>> getFirstValue = termAndPosition.lastEntry();
			Vector<Integer> vector = getFirstValue.getValue();
			Collections.sort(vector);
			maxLenVector = vector.size() - 1;
	
			return possition = new Position(getFirstValue.getKey() , vector.get(maxLenVector));
		}
		
		public Position lastDoc(String key){
			
			return possition;
		}
		
		public Position prev(String key, int p){
			
			return possition;
		}
		
		public Position prevDoc(String key, int p){
			
			return possition;
		}
		
	}
		
}


